package com.test.drawing;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.microedition.khronos.opengles.GL10;

/**
 * Group that holds a set of Meshes.
 */
public class Group implements Drawable, Iterable<Drawable> {
    private final List<Drawable> mChildren = new ArrayList<Drawable>();

    @Override
    public void draw(GL10 gl) {
        for (Drawable child : mChildren) {
            child.draw(gl);
        }
    }

    /**
     * Adds a Drawable in the Group.
     * 
     * @param location
     *            Position of the new Mesh
     * @param object
     *            new Mesh
     */
    public void add(int location, Drawable object) {
        mChildren.add(location, object);
    }

    /**
     * Adds a Drawable in the Group.
     * 
     * @param object
     *            new Drawable
     * @return True - Added<br>
     *         False - Not Added
     */
    public boolean add(Drawable object) {
        return mChildren.add(object);
    }

    /**
     * Clears the group
     */
    public void clear() {
        mChildren.clear();
    }

    /**
     * Gets a Drawable from position.
     * 
     * @param location
     *            Position from the Drawable
     * @return Drawable from position
     */
    public Drawable get(int location) {
        return mChildren.get(location);
    }

    /**
     * Removes the Drawable from position.
     * 
     * @param location
     *            Position from the Drawable
     * @return Drawable removed
     */
    public Drawable remove(int location) {
        return mChildren.remove(location);
    }

    /**
     * Removes the Object from the Group.
     * 
     * @param object
     *            Object to be removed
     * @return True - Object Removed<br>
     *         False - Not Removed
     */
    public boolean remove(Object object) {
        return mChildren.remove(object);
    }

    /**
     * Size of the Group.
     * 
     * @return Group's Size
     */
    public int size() {
        return mChildren.size();
    }

    @Override
    public Iterator<Drawable> iterator() {
        return mChildren.iterator();
    }

}
